#include <stdio.h>
#include "nuclei_sdk_hal.h"
#include "nuclei_libopt.h"

#define ARR_SIZE 10
uint8_t uart0_send_buffer[ARR_SIZE]={ 0x01 ,0x02,0x03,0x04,0x05,0x06,0x07,0x08,0x09,0x0a};
uint8_t uart0_receive_buffer[ARR_SIZE]={0};

uint8_t uart0_send_buffer1[ARR_SIZE]={0x11, 0x12 ,0x13,0x14,0x15,0x16,0x17,0x18,0x19,0x1a};
uint8_t uart0_receive_buffer1[ARR_SIZE]={0};


ErrStatus memory_compare(uint8_t* src, uint8_t* dst, uint8_t length) 
{
    while(length--){
        if(*src++ != *dst++)
            return ERROR;
    }
    return SUCCESS;
}



void main(void )
{
    uart_init(UART0, 115200,UART_BIT_LENGTH_6);
    uart_config_stopbit(UART0,UART_STOP_BIT_0p5);

    int i=0,j=0,state0=0,state1=0;
    uart_clean_fifo(UART0);
    do{
        uart_write(UART0,uart0_send_buffer[i]);
        uart0_receive_buffer[i]=uart_read(UART0);
    }while((++i)<ARR_SIZE);

    state0=memory_compare(uart0_send_buffer,uart0_receive_buffer,ARR_SIZE);

    uart_init(UART0, 256000,UART_BIT_LENGTH_7);
    uart_config_stopbit(UART0,UART_STOP_BIT_1p5);

    i=0,j=0;
    uart_clean_fifo(UART0);
    do{
        uart_write(UART0,uart0_send_buffer1[i]);
        uart0_receive_buffer1[i]=uart_read(UART0);
    }while((++i)<ARR_SIZE);

    state1=memory_compare(uart0_send_buffer1,uart0_receive_buffer1,ARR_SIZE);
 
 
    gpio_enable_output(GPIO,1 <<0 );
    gpio_enable_output(GPIO,1 <<1 );

    while(1)
    {
        if(state0&state1)
        {
            gpio_toggle(GPIO_TypeDef *gpio, 1 <<0) ;    
        }
        else
        {
            gpio_toggle(GPIO_TypeDef *gpio, 1 <<1) ;  
        }
    }
 
    return 0;
}
